/**
 * Created by LangK on 2016/12/20.
 */
var path = require('path');
var http = require('http');
var express = require('express');
var proxyMiddleware = require('http-proxy-middleware')
var proxy = require('express-http-proxy')

require("./config/config.js")
var app = express()




app.use(express.static(path.join(__dirname, '/dist/')))
var port = 3034
app.set('port', port)
var proxyTable = {
  '/auth/login': {
    target: "http://" + global.logIp + ":" + global.logport,
    changeOrigin: true
  },
  '/admin/info': {
    target: "http://" + global.logIp + ":" + global.logport,
    changeOrigin: true
  },
  '/admin/consumer': {
    target: "http://" + global.logIp + ":" + global.logport,
    changeOrigin: true
  },
  '/admin/goods': {
    target: "http://" + global.logIp + ":" + global.logport,
    changeOrigin: true
  },
  '/admin/notice': {
    target: "http://" + global.logIp + ":" + global.logport,
    changeOrigin: true
  },
  '/admin/order': {
    target: "http://" + global.logIp + ":" + global.logport,
    changeOrigin: true
  },
  '/admin/store_info': {
    target: "http://" + global.logIp + ":" + global.logport,
    changeOrigin: true
  },
  '/api/file': {
    target: "http://" + global.logIp + ":" + global.logFileport,
    changeOrigin: true
  },
  '/admin/log': {
    target: "http://" + global.logIp + ":" + global.logport,
    changeOrigin: true
  },
  '/admin/type': {
    target: "http://" + global.logIp + ":" + global.logport,
    changeOrigin: true
  },
  '/client/home': {
    target: "http://" + global.logIp + ":" + global.logport,
    changeOrigin: true
  },
  '/admin/about': {
    target: "http://" + global.logIp + ":" + global.logport,
    changeOrigin: true
  },
  '/admin/msg': {
    target: "http://" + global.logIp + ":" + global.logport,
    changeOrigin: true
  },
  '/admin/cash': {
    target: "http://" + global.logIp + ":" + global.logport,
    changeOrigin: true
  },
  '/client/store_admin': {
    target: "http://" + global.logIp + ":" + global.logport,
    changeOrigin: true
  },
  '/client/activity': {
    target: "http://" + global.logIp + ":" + global.logport,
    changeOrigin: true
  }
}

Object.keys(proxyTable).forEach(function (context) {
  var options = proxyTable[context]
  if (typeof options === 'string') {
    options = { target: options }
  }
  app.use(proxyMiddleware(context, options))
})


var server = http.createServer(app);

server.listen(port);
app.listen(80, function () {
  console.log('server start')
})